package com.har.modules.web.controller;


import com.har.common.exception.RRException;
import com.har.common.utils.R;
import com.har.modules.web.entity.ApplyEntity;
import com.har.modules.web.entity.SmartStoreEntity;
import com.har.modules.web.service.RegiserService;
import com.har.modules.web.service.SmartStoreService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;

/**
 * 智慧门店
 *
 * @author maorui
 *
 */
@Slf4j
@RestController
@RequestMapping("/smartstore")
public class SmartStoreController {

    @Autowired
    private SmartStoreService smartStoreService;

    @Autowired
    private RegiserService regiserService;

    /**
     *
     *   通过产品类型名称查询智慧门店详细信息/wechat共用
     *
     * @return
     */
    @RequestMapping("/info")
    public R info(){
        SmartStoreEntity smartStoreEntity=smartStoreService.selectOne();
        if (null==smartStoreEntity) {
            throw new RRException("查询出错");
        }
        return R.ok().put("data", smartStoreEntity);
    }



    /**
     *    智慧门店页面申请
     * @param applyEntity
     * @param
     * @return
     */
    @RequestMapping("/save")
    public R save(@RequestBody ApplyEntity applyEntity, HttpServletRequest request) throws ParseException {
        applyEntity.setProductTypeName("智慧门店");
        //保存申请内容
        regiserService.save(applyEntity,request);

        return R.ok();
    }
}
